package com.flyme.module.exam.provider.service.impl;


import com.flyme.common.core.utils.ApiAssert;
import com.flyme.core.base.supper.service.impl.BaseServiceImpl;
import com.flyme.module.exam.client.entity.ExamOpt;
import com.flyme.module.exam.client.vo.ExamItem;
import com.flyme.module.exam.provider.mapper.ExamOptMapper;
import com.flyme.module.exam.provider.service.ExamOptService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author: flyme
 * @date: 2018/3/7 15:27
 * @desc: 题库选项管理接口实现
 */
@Service
public class ExamOptServiceImpl extends BaseServiceImpl<ExamOptMapper, ExamOpt> implements ExamOptService {

    @Override
    public List<ExamItem> selectList(Long examId) {
        List<ExamOpt> examOpts = list(q().eq("examId", String.valueOf(examId)));
        List<ExamItem> examItems = new ArrayList<>();
        int i = 1;
        for (ExamOpt examOpt : examOpts) {
            ExamItem examItem = new ExamItem();
            examItem.setCorrect(examOpt.getCorrect());
            examItem.setIndex(i++);
            examItem.setStatus(1);
            examItem.setValue(examOpt.getExamOptionName());
            examItems.add(examItem);
        }

        return examItems;
    }

    @Override
    public Boolean deleteByExamId(Long examId) {
        ApiAssert.notNull("examId不能为空", examId);
        return remove(q().eq(true, "examId", examId));
    }

    /**
     * 根据题目查询答案
     */
    public List<Map<String, Object>> selectByExam(String examId){
        return listMaps(q().select("id","examOptionName","examOptionCode","correct").eq("examId", examId));
    }
}
